package com.demo.function.easypoi;

import cn.afterturn.easypoi.handler.inter.IExcelExportServer;
import com.alibaba.fastjson.JSON;
import com.demo.model.entity.es.OrderHeader;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Excel 大数据量导出实现类
 * @author cyj
 **/
@Slf4j
@Service
public class ExcelService implements IExcelExportServer {

    /**
     * 大数据量导出必须实现IExcelExportServer接口
     * @param o 对应key=BigExcelConstants.DATA_PARAMS的值
     * @param i 循环次数
     * @return 返回集合
     */
    @Override
    public List<Object> selectListForExcelExport(Object o, int i) {
        log.info("参数，o:{}, i:{}", JSON.toJSONString(o), i);
        List<Object> list = Lists.newArrayList();
        if (i > 5) {
            return Lists.newArrayList();
        }

        for (long j = 0; j < 5000; j++) {
            OrderHeader orderHeader = new OrderHeader();
            orderHeader.setOrderId(j);
            orderHeader.setDateOfPurchase(new Date());
            list.add(orderHeader);
        }
        return list;
    }
}
